﻿//Write a method that checks if the element at given position in given array of
//integers is bigger than its two neighbors (when such exist).


using System;
using System.Text;

public class ChecksNeighbors
{
    public static void Main()
    {
        Console.Write("Enter length of array L = ");
        int length = int.Parse(Console.ReadLine());
        double[] array = new double[length];
        PopulateArray(array);
        PrintArray(array);

        Console.Write("\nEnter element index to check in range[1...{0}] Index = ", array.Length);
        int index = int.Parse(Console.ReadLine()) - 1;
        Console.WriteLine("Element at index {0} is {1}", index + 1, array[index] );

        string side = "left";
        for (int i = index - 1; i <= index + 1; i++)
        {
            if ((i >= 0) && (i < array.Length) && (i != index))
            {
                string result = Check(array, index, i, side);
                Console.WriteLine(result);
            }
            else
            {
                side = (i + 1 > index ? "right" : "");
                continue;
            }
        }
    }

    private static string Check(double[] array, int elementIndex, int currentIndex, string side)
    {
        if (array[elementIndex] > array[currentIndex])
        {
            return string.Format("Element at index {0} is great than {1} element", elementIndex + 1, side);
        }
        else if (array[elementIndex] < array[currentIndex])
        {
            return string.Format("Element at index {0} is small than {1} element", elementIndex + 1, side);
        }
        else
        {
            return string.Format("Element at index {0} is equal to {1} element", elementIndex + 1, side);
        }
    }

    private static void PopulateArray(double[] array)
    {
        Random rand = new Random();
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = rand.Next(-99, 100);
        }
    }

    private static void PrintArray(double[] array)
    {
        Console.Write("{");
        for (int i = 0; i < array.Length; i++)
        {
            if (i == array.Length - 1)
            {
                Console.Write("{0}}}", array[i]);
            }
            else
            {
                Console.Write("{0}, ", array[i]);
            }
        }

        Console.WriteLine();
    }
}